package gao.xaiolei.config;

import java.io.File;

import javax.servlet.MultipartConfigElement;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;
import xiaolei.gao.Image.ImageInterface;
import xiaolei.gao.file.FileInterface;

@Configuration
public class ConfigBean {

	@Bean
	@LoadBalanced
	public RestTemplate restTemplate() {
		return new RestTemplate();
	}

	@Bean
	MultipartConfigElement multipartConfigElement() {
		MultipartConfigFactory factory = new MultipartConfigFactory();
		String location = System.getProperty("user.dir") + "/data/tmp";
		File tmpFile = new File(location);
		if (!tmpFile.exists()) {
			tmpFile.mkdirs();
		}
		factory.setLocation(location);
		return factory.createMultipartConfig();
	}

	@Bean("FileInterface")
	@Autowired
	public FileInterface fileInterface(RestTemplate restTemplate){
		return new FileInterface(restTemplate);
	}

	@Bean("ImageInterface")
	@Autowired
	public ImageInterface imageInterface(RestTemplate restTemplate){
		return new ImageInterface(restTemplate);
	}

}
